import { Client, logger, Variables }  from 'camunda-external-task-client-js';
import open from 'open';

const config = { baseUrl: 'http://43.142.80.140:10030/engine-rest', use: logger, asyncResponseTimeout: 10000 };

const client = new Client(config);

client.subscribe('pay', { processDefinitionKey: 'Process_shopping' },
    async function({ task, taskService }) {
        const size = task.variables.get('size');
        const count = task.variables.get('count');

        console.log(`顾客下单尺寸: ${size} 数量: '${count}' ...`)

        const processVariables = new Variables()
            .set("toWhere", "shanghai China");

        try {
            await taskService.complete(task, processVariables);
            console.log("I completed my task successfully !!");
        } catch(e) {
            console.error(`Failed completing my task, ${e}`);
        }
    });
